package com.mobile.weather.controller;

import com.mobile.weather.client.CityListClient;
import com.mobile.weather.client.WeatherAPIClient;
import com.mobile.weather.domain.City;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
public class WeatherController {
    @Autowired
    CityListClient cityListClient;

    @Autowired
    WeatherAPIClient weatherAPIClient;

    ThymeleafProperties thymeleafProperties;

    @RequestMapping("/weather")
    public String weather(){
       // return new ModelAndView("weather"); //  /templates/weather.html
        return "weather";
    }

    @RequestMapping("/weather2/{city}")
    public ModelAndView weather2(Model model,@PathVariable("city") String city){

        //调用service  访问第三方接口获取天气数据
        List<City> cityList=cityListClient.cityList();

        //把这个城市列表数据给页面
        model.addAttribute("cityList",cityList);

        model.addAttribute("cityIdArgs",city);

        ThymeleafProperties th;  //  /templates/weather.html
        return new ModelAndView("test","weatherdata",weatherAPIClient.weather(city));


        //return new ModelAndView("test","content","这个内容会替换掉原有的内容");
    }
}
